import 'package:flutter/material.dart';

// import '../../config/common_colors.dart';
// import '../../generated/l10n.dart';

class BottomKeyBoard extends StatefulWidget {
  final TextEditingController controller;
  final Function(bool hasFocus) inPutListen;
  final Function(String message) messageSend;
  final Function() expressionOnClick;

  const BottomKeyBoard(
      {super.key,
      required this.controller,
      required this.expressionOnClick,
      required this.inPutListen,
      required this.messageSend});

  @override
  State<StatefulWidget> createState() => ViewState();
}

class ViewState extends State<BottomKeyBoard> {
  final FocusNode _focusNode = FocusNode();

  @override
  void initState() {
    super.initState();
    _focusNode.addListener(_onFocusChange);
  }

  void _onFocusChange() {
    widget.inPutListen(_focusNode.hasFocus);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        height: 56,
        padding: const EdgeInsets.symmetric(vertical: 10),
        child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.max,
            children: [
              //
              Expanded(
                  child: Stack(fit: StackFit.expand, children: [
                Container(
                  alignment: Alignment.center,
                  decoration: const BoxDecoration(
                      image: DecorationImage(
                          fit: BoxFit.fill,
                          image: AssetImage('images/icon_btn_bg_comment.png'))),
                  child: TextField(
                    focusNode: _focusNode,
                    controller: widget.controller,
                    style: const TextStyle(color: Colors.black),
                    decoration: InputDecoration(
                        contentPadding: const EdgeInsets.only(
                            left: 12, top: 2, bottom: 2, right: 2),
                        filled: true,
                        // fillColor: Colors.white,
                        // 背景颜色
                        hintText: 'Enter your ideas...',
                        hintStyle: const TextStyle(color: Color(0x4D000000)),
                        border: OutlineInputBorder(
                          // borderRadius: BorderRadius.circular(18),
                          // 设置圆角半径
                          borderSide: BorderSide.none, // 将边框置为空
                        )),
                  ),
                )
              ])),
              const SizedBox(width: 12),
              Container(
                  margin: EdgeInsets.only(
                    right: 6,
                  ),
                  child: InkWell(
                      onTap: () {
                        if (widget.controller.text.trim().isNotEmpty) {
                          widget.messageSend(widget.controller.text);
                          widget.controller.text = "";
                        }
                      },
                      // icon_coin_bg_mine
                      child: Container(
                        decoration: const BoxDecoration(
                            image: DecorationImage(
                                fit: BoxFit.fill,
                                image: AssetImage(
                                    'images/icon_coin_bg_mine.png'))),
                        width: 67,
                        height: 56,
                        // color: Colors.yellow,
                        alignment: Alignment.center,
                        child: Text(
                          'Send',
                          style:
                              TextStyle(color: Color(0xFFE71988), fontSize: 16),
                        ),
                      ))),
              const SizedBox(width: 12),
              // InkWell(
              //     onTap: widget.expressionOnClick,
              //     child: Image.asset(
              //         height: 36,
              //         width: 36,
              //         "images/ic_expression_color.webp")),
              // const SizedBox(width: 12),
            ]));
  }

  @override
  void dispose() {
    super.dispose();
    _focusNode.removeListener(_onFocusChange);
    _focusNode.dispose();
  }
}
